package com.xinruke.hostels.dailymanage.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.dailymanage.interfaces.dto.*;
import com.xinruke.hostels.dailymanage.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.validation.Valid;
/**
 * @ClassName CommentController
 * @date：2019/6/21
 * @author GuoZheng
 * @version: 1.0
 * @description：评论管理
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论管理")
public class CommentController extends BaseController {

    @Resource
    CommentService commentService;

    /**
     * 评论列表
     *
     * @param
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "评论列表")
    public ResultVO<RowsDataVO<CommentInfoQueryResultDTO>> list(@RequestBody @Valid CommentInfoQueryDto commentInfoQueryDto) {
        ResultVO<RowsDataVO<CommentInfoQueryResultDTO>> resultVO = ResultVO.fail();
        RowsDataVO<CommentInfoQueryResultDTO> dataVO =  commentService.list(commentInfoQueryDto);

            resultVO.setCode(ResultVO.SUCCESS);
            resultVO.setMessage("success");
            resultVO.setData(dataVO);
        return resultVO;
    }
    /**
     * 评论平均分
     *
     * @param
     * @return
     */
    @GetMapping("/average/{id}")
    @ApiOperation(value = "评论平均分")
    @ApiIgnore
    public CommentAverageResultDto average(@PathVariable("id") Integer id) {
        return commentService.average(id);

    }

    /**
     * 提交商品评价信息
     *
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("提交评论")
    public ResultVO<String> submit(@Valid @RequestBody CommentSubmitInfoDto params) {
        return commentService.submit(params);
    }

    /**
     * 得到订单的评价信息
     *
     */
    @PostMapping("/detail")
    @ApiOperation("评论详情")
    public ResultVO<CommentDetailQueryResultDTO> detail(@Valid @RequestBody CommentDetailQueryDTO params) {
        return commentService.detail(params);
    }


    /**
     * 删除
     *todo 什么时候可以删除
     */
    @PostMapping("/del")
    @ApiOperation("删除评论信息")
    public ResultVO<String> del(@Valid @RequestBody CommentDelQueryDTO params) {
        return commentService.del(params);
    }


    /**
     * 审核评论
     *
     */
    @PostMapping("/audit")
    @ApiOperation("审核评论")
    public ResultVO<String> audit(@Valid @RequestBody CommentAuditQueryDTO params) {
        return commentService.audit(params);
    }



}
